package com.insurance.modules.claim.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.insurance.common.common.ResponseData;
import com.insurance.common.utils.QueryList;
import com.insurance.common.utils.R;
import com.insurance.modules.claim.entity.ContactRecordEntity;
import com.insurance.modules.claim.service.ContactRecordService;
import com.insurance.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * 理赔沟通（案件情况）记录表
 *
 * @author weiruifeng
 * @email
 * @date 2021-09-24 17:42:47
 */
@RestController
@RequestMapping("claim/contactrecord")
@Api(tags = "理赔沟通（案件情况）记录")
public class ContactRecordController extends AbstractController {
    @Autowired
    private ContactRecordService contactRecordService;

    /**
     * 列表
     */
    @PostMapping("/pageList")
    //@RequiresPermissions("claim:contactrecord:pageList")
    //@ApiOperation(value = "查询列表", notes = "根据条件查询列表")
    public ResponseData<Page<ContactRecordEntity>> pageList(@RequestBody QueryList<String> param) {
        Page<ContactRecordEntity> page = new Page<>(param.getPage(), param.getPageSize());
        page = contactRecordService.pageList(page, param.getParams());
        return ResponseData.success(page);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("claim:contactrecord:save")
    //@ApiOperation(value = "保存信息", notes = "保存信息")
    public R save(@RequestBody ContactRecordEntity contactRecord) {
        if(StringUtils.isBlank(contactRecord.getCsId())){
            return R.error("参数错误，请刷新页面后重试!");
        }
        if (contactRecord.getContactTime() == null) {
            contactRecord.setContactTime(new Date());
        }
        Date date = new Date();
        contactRecord.setCreateBy(getUserId());
        contactRecord.setCreateTime(date);
        contactRecord.setUpdateBy(getUserId());
        contactRecord.setUpdateTime(date);
        contactRecordService.save(contactRecord);
        return R.ok();
    }

}
